<?php $this->load->module('mobile/index/header', $common);?>

<link rel="stylesheet" type="text/css" href="<?php echo URLPRE;?>static/template/default/mobile/css/main.css" />
<link rel="stylesheet" type="text/css" href="<?php echo URLPRE;?>static/template/default/mobile/css/dialog.css" />
<link rel="stylesheet" type="text/css" href="<?php echo URLPRE;?>static/template/default/mobile/css/base.css" />
<link rel="stylesheet" type="text/css" href="<?php echo URLPRE;?>static/template/default/mobile/css/index.css" />
<link rel="stylesheet" type="text/css" href="<?php echo URLPRE;?>static/template/default/mobile/css/line.css" />
<script type="text/javascript" src="<?php echo URLPRE;?>static/template/default/mobile/js/mobilecommon.js"></script>
<script type="text/javascript" src="<?php echo URLPRE;?>static/template/default/mobile/js/slider.js"></script>
<script type="text/javascript" src="<?php echo URLPRE;?>static/template/default/mobile/js/dialog.js"></script>
<link rel="stylesheet" type="text/css" href="<?php echo URLPRE;?>static/template/default/mobile/css/flight.css" />
<script type="text/javascript">
        var scity = '<?php echo $scity ;?>' ;
        var scityname = '<?php echo $scityname ;?>' ;
        var ecity = '<?php echo $ecity ; ?>' ;
        var ecityname = '<?php echo $ecityname ; ?>' ;
        var sdate = '<?php echo $sdate ;?>' ;
        <?php if($isLogin):?>
        var isLogin = 1 ;
        <?php else:?>
        var isLogin = 0 ;
        <?php endif;?>
    </script>
<?php
// 重组数据结构
if(isset($list)&&!empty($list)&&count($list)==2)
{
    $list[0]['@attributes'] = $list['@attributes'];
    $list[0]['Cabin'] = $list['Cabin'];
    unset($list['@attributes']);
    unset($list['Cabin']);
}
?>
    <div class="content">
        <div id="js_FlightMenuFrame2" class="type_date">
            <ul class="tab_time flight-listdate">
                <li class="yesterday t1" <?php if(strtotime($pre_date)==strtotime(date('Y-m-d',time()))):?> id="pre_date_search_f" <?php endif;?> date="<?php echo $pre_date ;?>" >
                    <div>前一天</div>
                </li>
                <li class="today t2">
                    <div class="date">
                        <i class="flight-cheap-calendar">低</i>
                        <label id="js_CurDate"><a href="<?php echo site_url('mobile/flight/index?scity='.$scityname.'&ecity='.$ecityname);?>"><?php echo $current_date;?></a> </label>
                    </div>
                </li>
                <li class="tomorrow t3" id="next_date_search_f" date="<?php echo $next_date;?>">
                    <div>后一天</div>
                </li>
            </ul>
        </div>
        <div id="theFlightlist">
<?php  if(isset($list)&&!empty($list)):?>
    <?php  foreach($list as $k=>$v): ?>
            <ul class="f_list_tab">
                <li class="f_info js_flight_item" style="box-sizing: border-box;width:100%;" >
                    <div class="flight-list-start">
                        <p><span class="fnt-18"><?php echo $v['@attributes']['Stime'] ; ?></span></p>
                        <p><?php echo $v['@attributes']['Scity'] ; ?></p>
                    </div>
                    <div class="flight-list-middle">
                        <i class="flight-icon-fx"></i>
                    </div>
                    <div class="flight-list-end">
                        <p><span class="fnt-18"><?php echo $v['@attributes']['Etime'] ; ?></span></p><p><?php echo $v['@attributes']['Ecity'] ;?></p>
                    </div>
                    <div class="flight-list-hs" style="width:95%;white-space: nowrap; overflow: hidden; text-overflow: ellipsis;">
                        <span><?php echo airline_word_to_name($v['@attributes']['AirLine']);?><?php echo $v['@attributes']['FlightNo'] ;?></span>
                    </div>
                </li>
                <li class="f_price js_flight_item" data-key="1" data-cabin-key="0">
                    <dfn>¥</dfn>
                    <strong><?php echo ceil($v['Cabin'][0]['@attributes']['P']-(($v['Cabin'][0]['@attributes']['P']*($v['Cabin'][0]['@attributes']['K']-1))/100)) ;?>起</strong>
                </li>
        <?php if(count($v['Cabin'])>1): ?>
                <li class="flight-listfold flight-packdown js_subswitch cabin_switch" >
                    <em>更多舱位</em>
                </li>
        <?php endif ;?>
            </ul>
            <ul class="js_sublist f_detail cabin_box" style="display:none;" Stime="<?php echo $v['@attributes']['Stime'];?>" Etime="<?php echo $v['@attributes']['Etime'] ; ?>" Fchange="<?php echo $val['@attributes']['Change'];?>" Freturn="<?php echo $val['@attributes']['Return'] ;?>" Fees="<?php echo $v['@attributes']['Fees'] ; ?>" Airtax="<?php echo $v['@attributes']['AirTax'] ; ?>">
        <?php if(!empty($v['Cabin'])&&isset($v['Cabin'])):?>
            <?php foreach ($v['Cabin'] as $key=>$val):?>
                <?php if($val['@attributes']['P'] !=='0'&&!empty($val['@attributes']['C'])):?>
                <li class="js_flight_seat">
        <span class="xq_info">优选套餐<em class="xq-yp clr-red"><span style="color:#f00">
                    <?php if($val['@attributes']['N']=='A'):?>
                        >9
                    <?php else:?>
                        仅剩<?php echo $val['@attributes']['N'] ;?>
                    <?php endif ;?>张</span></td></span></em></span>
          <span class="xq_price"><span class="flight-btn-price"><dfn>¥</dfn><strong><?php echo ceil($val['@attributes']['P']-(($val['@attributes']['P']*($val['@attributes']['K']-1)/100)));?></strong></span>
<button class="flt-btn-yellow btn_book" Price="<?php echo $val['@attributes']['P'] ;?>"  RateId="<?php echo $val['@attributes']['ID'] ;?>" PolicyId="<?php echo $val['@attributes']['RID'] ;?>" Airline="<?php echo $v['@attributes']['FlightNo'];?>" Cabins="<?php echo $val['@attributes']['C'] ;?>" DotNum="<?php echo $val['@attributes']['K'] ;?>">预订</button></span>
                </li>
                <?php endif ;?>
            <?php endforeach ;?>
        <?php endif ;?>
            </ul>
    <?php endforeach ; ?>
<?php endif;?>
        </div>
</div>
<?php $this->load->module('mobile/index/footer', $common);?>
<script type="text/javascript">
    $(function(){
      $('.cabin_switch').click(function(){
          var $target = $(this).closest('ul').next('ul');
          if($target.is(":hidden")){
              $target.show();
          }else{
              $target.hide();
          }
      })
        $('#next_date_search_f').click(function(){
            $.dialog({
                style:'tip',
                width:200,
                closeTime:1000,
                content: '<p style="text-align: center">加载中...</p>'
            }).open();
            var sdate = $(this).attr('date');
            var flight_url = '<?php echo site_url('mobile/flight/flight_list?param=');?>';
            var url = flight_url+''+scityname+'_'+ecityname+'_'+sdate ;
            window.location.href = url ;
        })
        $('#pre_date_search_f').click(function(){
            $.dialog({
                style:'tip',
                width:200,
                closeTime:1000,
                content: '<p style="text-align: center">加载中...</p>'
            }).open();
            var sdate = $(this).attr('date');
            var flight_url = '<?php echo site_url('mobile/flight/flight_list?param=');?>';
            var url = flight_url+''+scityname+'_'+ecityname+'_'+sdate ;
            window.location.href = url ;
        })
        $('.btn_book').on('click',function(){
            if(isLogin==0)
            {
                var url = '<?php echo site_url('mobile/member/login?referer='.$_SERVER['REQUEST_URI']) ;?>';
                window.location.href = url ;
            }
            var RateId   = $(this).attr('rateid');
            var PolicyId = $(this).attr('policyid');
            var Cabins   = $(this).attr('cabins');
            var Airline  = $(this).attr('airline');
            var Price  = $(this).attr('price');
            var Sdate    = sdate ;
            var Scity    = scity ;
            var Ecity    = ecity ;
            var DotNum   = $(this).attr('dotnum');
            var Stime = $(this).closest('ul').attr('Stime');
            var Etime = $(this).closest('ul').attr('Etime');
            var Fees =  $(this).closest('ul').attr('Fees');
            var Airtax = $(this).closest('ul').attr('Airtax');
            var f_change =   $(this).closest('ul').attr('Fchange');
            var f_return =   $(this).closest('ul').attr('Freturn');
            var url = '<?php echo site_url('mobile/flight/book_initialize'); ?>' ;
            var referer =   '<?php echo 'http://'.$_SERVER['HTTP_HOST'].$_SERVER['REQUEST_URI'] ;?>' ;
            $.post(url,{
                RateId:RateId,
                PolicyId:PolicyId,
                Cabins:Cabins,
                Airline:Airline,
                Sdate:Sdate,
                Scity:Scity,
                Ecity:Ecity,
                DotNum:DotNum,
                Stime:Stime,
                Etime:Etime,
                Price:Price,
                Fees:Fees,
                Airtax:Airtax,
                f_change:f_change,
                f_return:f_return,
                referer:referer
            },function(json){
                if(json.status=='1'){
                    $.dialog({
                        style:'tip',
                        width:200,
                        closeTime:1000,
                        content: '<p style="text-align: center">初始化...</p>'
                    }).open();
                    window.location.href=json.url;
                }
            },"json")
        })
    })
   </script>